package org.istt.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

/**
 * File entity. @author MyEclipse Persistence Tools
 */
@Entity(name = "file")
@Table(name = "TBL_FILE", schema = "dbo", catalog = "onegate")
public class File extends BaseObject<String> implements java.io.Serializable {

	public static final int AMEND = 3;
	/*
	 * 
	 */
	public static final int BEGIN = 1;
	public static final int COMPLETED = 4;
	public static final int FINISH = 5;
	public static final int IN_PROGRESS = 2;
	/**
	 * 
	 */
	private static final long serialVersionUID = -7537235430889647821L;
	
	public static final int WAITTING_APPROVE = 6;
	private String address;
	private Set<AttachFileDetail> attachFileDetails = new HashSet<AttachFileDetail>(0);
	private Category category;
	
	private CategoryType categoryType;
	private String construct;
	private String contactFax;
	//Nguoi lien he
	private String contactName;
	
	private String contactPhone;
	private User createdBy;
	private User currentUser;
	private String currentUserFullName;
	
	
	private DateTime dateCompleted;
	private DateTime dateGetResult;
	private Set<Exchange> exchanges = new HashSet<Exchange>(0);
	private Set<FileManagement> fileManagements = new HashSet<FileManagement>(0);
	private FileStatus fileStatus;
	// Fields
	/* FileCode + YYYYMMDDHHMMSS */
	private String id;
	private DateTime inputDate;
	private String location;
	private Integer number;
	private String organization;
	private String orgFax;
	private String orgPhone;
	private String otherAttachFiles;
	
	private DateTime outputDate;
	private String oversea;
	private String overseaFax;
	private String overseaPhone;
	private String receiver;
	private String receiver_info;
	//Nguoi nop
	private String sender;
	private String senderPhone;
	private SubCategory subCategory;
	//Nguoi dung ten
	private String submitter;
	private String consultantName;
	private String consultantPhone;
	private String consultantAdd;

	// Constructors

	/** default constructor */
	public File() {
	}

	public void addAttachFileDetail(AttachFileDetail item) {
        if (item == null) throw new IllegalArgumentException("Null item!");
        attachFileDetails.add(item);
        item.setFile(this);
    }

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof File)) return false;

		final File ps = (File) o;


        if (!getId().equals(ps.getId())) return false;

		return true;
	}

	/**
	 * Dia chi lien he
	 * @return
	 */
	@Column(name = "ADDRESS", length = 500)
	public String getAddress() {
		return address;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "file")
	public Set<AttachFileDetail> getAttachFileDetails() {
		return attachFileDetails;
	}
	
	/**
	 * Loai Thu Tuc Hanh Chinh
	 * @return
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CATEGORY_ID", nullable = false)
	public Category getCategory() {
		return this.category;
	}
	
	/**
	 * Loai TTHC
	 * @return
	 */
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="CATEGORY_TYPE_ID")
	public CategoryType getCategoryType() {
		return categoryType;
	}

	/**
	 * Ten cong trinh
	 * @return
	 */
	@Column(name = "CONSTRUCT")
	public String getConstruct() {
		return construct;
	}

	@Column(name = "CONTACT_FAX")
	public String getContactFax() {
		return contactFax;
	}
	
	/**
	 * Ten Nguoi lien he
	 * @return
	 */
	@Column(name = "CONTACT_NAME")
	public String getContactName() {
		return contactName;
	}

	/**
	 * Dien Thoai Lien He
	 * @return
	 */
	@Column(name = "CONTACT_PHONE")
	public String getContactPhone() {
		return contactPhone;
	}
	
	/**
	 * Nguoi tiep nhan ho so
	 * @return
	 */
	@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="CREATED_BY")
	public User getCreatedBy() {
		return createdBy;
	}

	@Transient
	public User getCurrentUser() {
		return currentUser;
	}

	@Transient
	public String getCurrentUserFullName() {
		return currentUserFullName;
	}

	@Column(name = "DATE_COMPLETED")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getDateCompleted() {
		return dateCompleted;
	}

	@Column(name = "DATE_GET_RESULT")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getDateGetResult() {
		return dateGetResult;
	}

	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="file")	
	public Set<Exchange> getExchanges() {
		return this.exchanges;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "file")
	public Set<FileManagement> getFileManagements() {
		return this.fileManagements;
	}

	/**
	 * Trang thai hien tai cua ho so
	 * @return
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "FILE_STATUS_ID")
	public FileStatus getFileStatus() {
		return this.fileStatus;
	}
	
	/**
	 * Ma bien nhan ho so
	 */
	@Id
	@Column(name = "ID", unique = true, nullable = false)
	public String getId() {
		return this.id;
	}

	/**
	 * Ngay Nop HS
	 * @return
	 */
	@Column(name = "INPUT_DATE")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getInputDate() {
		return this.inputDate;
	}

	/**
	 * Dia diem xay dung
	 * @return
	 */
	@Column(name = "LOCATION")
	public String getLocation() {
		return location;
	}

	/**
	 * it starts at 1 on 13th and plus one each day until 12th
	 * @return
	 */
	@Column(name = "NUMBER", updatable = false)
	public Integer getNumber() {
		return number;
	}
	/**
	 * Ten Chu Dau Tu
	 * @return
	 */
	@Column(name = "ORGANIZATION")
	public String getOrganization() {
		return this.organization;
	}

	/**
	 * FAX Chu dau tu
	 * @return
	 */
	@Column(name = "ORG_FAX", length = 15)
	public String getOrgFax() {
		return orgFax;
	}

	/**
	 * Dien thoai Chu Dau Tu
	 * @return
	 */
	@Column(name = "ORG_PHONE", length = 15)
	public String getOrgPhone() {
		return this.orgPhone;
	}

	/**
	 * Giay to kem theo khacs
	 * @return
	 */
	@Column(name = "OTHER_ATTACH_FILES")
	public String getOtherAttachFiles() {
		return this.otherAttachFiles;
	}
	/**
	 * Ngay Hen Tra HS
	 * @return
	 */
	@Column(name = "OUTPUT_DATE")
	@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getOutputDate() {
		return this.outputDate;
	}

	/**
	 * Nha thau nuoc ngoai
	 * @return
	 */
	@Column(name = "OVERSEA")
	public String getOversea() {
		return oversea;
	}
	
	/**
	 * Fax nha thau nuoc ngoai
	 * @return
	 */
	@Column(name = "OVERSEA_FAX")
	public String getOverseaFax() {
		return overseaFax;
	}

	/**
	 * DT nha thau nuoc ngoai
	 * @return
	 */
	@Column(name = "OVERSEA_PHONE")
	public String getOverseaPhone() {
		return overseaPhone;
	}

	@Column(name = "RECEIVER")
	public String getReceiver() {
		return receiver;
	}

	@Column(name = "RECEIVER_INFO")
	public String getReceiver_info() {
		return receiver_info;
	}
	/**
	 * Nguoi Dung Ten Ho So
	 * @return
	 */
	@Column(name = "SENDER")
	public String getSender() {
		return this.sender;
	}

	/**
	 * Dien Thoai nguoi den nop ho so
	 * @return
	 */
	@Column(name = "SENDER_PHONE", length = 15)
	public String getSenderPhone() {
		return this.senderPhone;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SUB_CATEGORY_ID")
	public SubCategory getSubCategory() {
		return subCategory;
	}

	/**
	 * Nguoi Dung Ten Ho So
	 * @return
	 */
	@Column(name="SUBMITTER")
	public String getSubmitter() {
		return submitter;
	}
	
	@Override
	public int hashCode() {
		int result;
		result = id.hashCode();
		result = 29 * result;
		return result;
	}

	public void removeAttachFileDetail(AttachFileDetail item) {
        if (item == null) throw new IllegalArgumentException("Null item!");
        attachFileDetails.remove(item);
        item.setFile(null);
    }
	public void setAddress(String address) {
		this.address = address;
	}

	public void setAttachFileDetails(Set<AttachFileDetail> attachFileDetails) {
		this.attachFileDetails = attachFileDetails;
	}
	public void setCategory(Category category) {
		this.category = category;
	}

	public void setCategoryType(CategoryType categoryType) {
		this.categoryType = categoryType;
	}
	public void setConstruct(String construct) {
		this.construct = construct;
	}

	public void setContactFax(String contactFax) {
		this.contactFax = contactFax;
	}

	public void setContactName(String contactName) {
		this.contactName = contactName;
	}

	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}
	public void setCurrentUser(User currentUser) {
		this.currentUser = currentUser;
	}

	public void setCurrentUserFullName(String currentUserFullName) {
		this.currentUserFullName = currentUserFullName;
	}
	public void setDateCompleted(DateTime dateCompleted) {
		this.dateCompleted = dateCompleted;
	}
	public void setDateGetResult(DateTime dateGetResult) {
		this.dateGetResult = dateGetResult;
	}

	public void setExchanges(Set<Exchange> exchanges) {
		this.exchanges = exchanges;
	}

	public void setFileManagements(Set<FileManagement> fileManagements) {
		this.fileManagements = fileManagements;
	}

	public void setFileStatus(FileStatus fileStatus) {
		this.fileStatus = fileStatus;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	public void setInputDate(DateTime inputDate) {
		this.inputDate = inputDate;
	}
	
	public void setLocation(String location) {
		this.location = location;
	}
    public void setNumber(Integer number) {
		this.number = number;
	}

	public void setOrganization(String organization) {
		this.organization = organization;
	}
	public void setOrgFax(String orgFax) {
		this.orgFax = orgFax;
	}
	
	public void setOrgPhone(String orgPhone) {
		this.orgPhone = orgPhone;
	}

	public void setOtherAttachFiles(String otherAttachFiles) {
		this.otherAttachFiles = otherAttachFiles;
	}
	
	public void setOutputDate(DateTime outputDate) {
		this.outputDate = outputDate;
	}

	public void setOversea(String oversea) {
		this.oversea = oversea;
	}
	
	public void setOverseaFax(String overseaFax) {
		this.overseaFax = overseaFax;
	}

	public void setOverseaPhone(String overseaPhone) {
		this.overseaPhone = overseaPhone;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}
	
	public void setReceiver_info(String receiver_info) {
		this.receiver_info = receiver_info;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public void setSenderPhone(String senderPhone) {
		this.senderPhone = senderPhone;
	}

	public void setSubCategory(SubCategory subCategory) {
		this.subCategory = subCategory;
	}

	public void setSubmitter(String submitter) {
		this.submitter = submitter;
	}
	@Override
	public String toString() {
		
		return null;
	}

	public void setConsultantPhone(String consultantPhone) {
		this.consultantPhone = consultantPhone;
	}
	@Column(name = "CONSULTANT_PHONE")
	public String getConsultantPhone() {
		return consultantPhone;
	}

	public void setConsultantName(String consultantName) {
		this.consultantName = consultantName;
	}
	@Column(name = "CONSULTANT")
	public String getConsultantName() {
		return consultantName;
	}

	public void setConsultantAdd(String consultantAdd) {
		this.consultantAdd = consultantAdd;
	}
	@Column(name = "CONSULTANT_ADD")
	public String getConsultantAdd() {
		return consultantAdd;
	}
	
}